package com.yyq.statistics.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yyq.statistics.entity.Daily;
import com.yyq.statistics.mapper.DailyMapper;
import com.yyq.statistics.service.DailyService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 网站统计日数据 服务实现类
 * </p>
 *
 * @author yyq
 * @since 2021-05-08
 */
@Service
public class DailyServiceImpl extends ServiceImpl<DailyMapper, Daily> implements DailyService {

    @Override
    public Map<String, Object> getChartData(String types, String begin, String end) {
        //查询数据库
        QueryWrapper<Daily> wrapper=new QueryWrapper<>();
        wrapper.between("date_calculated",begin,end);
        wrapper.select("date_calculated",types);
        List<Daily> dailies = baseMapper.selectList(wrapper);
        List<String> date=new ArrayList<>();
        List<Integer> num=new ArrayList<>();
        for (int i = 0; i < dailies.size(); i++) {

            date.add(dailies.get(i).getDateCalculated());
            switch (types) {
                case "register_num":
                    num.add(dailies.get(i).getRegisterNum());
                    break;
                case "login_num":
                    num.add(dailies.get(i).getLoginNum());
                    break;
                case "video_view_num":
                    num.add(dailies.get(i).getVideoViewNum());
                    break;
                case "course_num":
                    num.add(dailies.get(i).getCourseNum());
                    break;
                default:
                    break;
            }
        }
        Map<String,Object> map=new HashMap<>();
        map.put("date",date);
        map.put("num",num);

        return map;
    }
}
